<% content_for :content do %>

  <!-- widget grid -->
  <section id="widget-grid" class="">
  
    <!-- row -->
    <div class="row">
  
      <!-- NEW WIDGET START -->
      <article class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
  
        <!-- Widget ID (each widget will need unique ID)-->
        <div class="jarviswidget jarviswidget-color-blueDark" id="wid-id-3" data-widget-editbutton="false" data-widget-colorbutton="false" data-widget-deletebutton="false">
          <!-- widget options:
          usage: <div class="jarviswidget" id="wid-id-0" data-widget-editbutton="false">
  
          data-widget-colorbutton="false"
          data-widget-editbutton="false"
          data-widget-togglebutton="false"
          data-widget-deletebutton="false"
          data-widget-fullscreenbutton="false"
          data-widget-custombutton="false"
          data-widget-collapsed="true"
          data-widget-sortable="false"
  
          -->
          <header>
            <span class="widget-icon"> <i class="fa fa-table"></i> </span>
            <h2>电台列表</h2>
  
          </header>
  
          <!-- widget div-->
          <div>
  
            <!-- widget edit box -->
            <div class="jarviswidget-editbox">
              <!-- This area used as dropdown edit box -->
  
            </div>
            <!-- end widget edit box -->
  
            <!-- widget content -->
            <div class="widget-body no-padding">
              <div class="widget-body-toolbar">
                
              </div>
              <table id="datatable_tabletools" class="table table-striped table-hover vertical-align-middle">
                <thead>
                  <tr>
                    <th>#</th>
                    <th>台名</th>  
                    <th>节目预告</th>
                    <th>播放链接</th>
                    <th width='100'>操作</th>
                  </tr>
                </thead>
                <tbody>
                <% @televisions.each do |tv| %>
                  <tr id="television-<%= tv.id %>">
                    <td>
                      <%= image_tag "/assets/programs/#{tv.logo}" %>
                    </td>
                    <td>
                      <%= tv.name %>
                    </td>
                    <td>
                      <%- if tv.has_guide? %>
                        <%= link_to tv.guides_filename, [:admin, tv], remote: true, class: "hint  hint--bottom",
                         'data-hint' => "http://#{Rails.application.config.default_url_options[:host]}/guides/#{tv.guides_filename}" %>
                      <% else %>
                        <span class="label label-danger">无节目预告</span>
                      <% end %>
                    </td>
                    <td>
                      <%= link_to tv.play_url, tv.play_url, target: '_blank' %>
                    </td>
                    <td>
                      <%= link_to '编辑', edit_admin_television_path(tv), remote: true if current_admin.can?(controller: "admin/televisions", action: "edit") %>
                      <%= link_to "删除", admin_television_path(tv), method: :delete, remote: true, confirm: '是否确定删除?' if current_admin.can?(controller: "admin/televisions",action: "destroy") %>
                    </td>
                  </tr>
                  <% end %>
                </tbody>
              </table>
    
            </div>
            <!-- end widget content -->

          </div>
          <!-- end widget div -->

        </div>
        <!-- end widget -->

      </article>
      <!-- WIDGET END -->

    </div>
    
    <!-- end row -->
  
  </section>
  <!-- end widget grid -->
<% end %>
<% content_for :js do %>

  <script type="text/javascript">
  
    $(document).ready(function() {
      
      /* TABLE TOOLS */
      $('#datatable_tabletools').dataTable({
        "sDom" : "<'dt-top-row'Tlf>r<'dt-wrapper't><'dt-row dt-bottom-row'<'row'<'col-sm-6'i><'col-sm-6 text-right'p>>",
        "oTableTools" : {
          "aButtons" : [ 
              <% if current_admin.can?(controller: "admin/televisions", action: "new") %>
              {
                "sExtends":    "text",
                "sButtonText": '<%= link_to "添加电台", new_admin_television_path, :remote => true %>'
              }
              <% end %>
           ],
        },
        "bInfo": true,
        "fnInitComplete" : function(oSettings, json) {
          $(this).closest('#dt_table_tools_wrapper').find('.DTTT.btn-group').addClass('table_tools_group').children('a.btn').each(function() {
            $(this).addClass('btn-sm btn-default');
          });
        }
      });

    })

  </script>
<% end %>